package example.database.preparedstatments;

import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import jssia.database.statement.Keywords;
import example.database.example.JssiaTestInnodbTable;

public final class TestStatements {
    private TestStatements() {
    }

    public static final String INSERT_TEST_ROW = Keywords.INSERT_INTO + JssiaTestInnodbTable.TO_STRING + Keywords.SET + JssiaTestInnodbTable.DECIMAL_COL + Keywords.EQUALS + Keywords.VALUE;
    public static ResultSet insertTestRow(Connection conn, BigDecimal bigDecimal) throws SQLException {
        PreparedStatement insertTestRowStatement = conn.prepareStatement(INSERT_TEST_ROW, Statement.RETURN_GENERATED_KEYS);
        JssiaTestInnodbTable.DECIMAL_COL.set(insertTestRowStatement, 1, bigDecimal);
        insertTestRowStatement.executeUpdate();
        return insertTestRowStatement.getGeneratedKeys();
    }

    public static final String SELECT_TEST_BY_ID = Keywords.SELECT + JssiaTestInnodbTable.ID + Keywords._ + JssiaTestInnodbTable.DECIMAL_COL + Keywords.FROM + JssiaTestInnodbTable.TO_STRING + Keywords.WHERE + JssiaTestInnodbTable.ID + Keywords.EQUALS + Keywords.VALUE;
    public static ResultSet selectTestById(Connection conn, long id) throws SQLException {

        PreparedStatement selectTestByIdStatement = conn.prepareStatement(SELECT_TEST_BY_ID, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE);
        JssiaTestInnodbTable.ID.set(selectTestByIdStatement, 1, id);

        return selectTestByIdStatement.executeQuery();
    }
}
